To get started with the next section of our story, we're going to have to listen for when our basement
part gets touched.
When it does, we'll teleport all the players to the basement and start the cutscene for the stairs.
So let's get started.
We're going to be scripting in a total of five module scripts here, so you're going to want to make
sure you get all of these open.
For example, you want to open up the game service that is inside of your server script service.
Inside of your services folder.
You're going to want to open up the game sections module script that is inside of the module section,
and the service script service.
You're going to want to also open up your handsome Squidward Animate module script, which is also in
the modules folder in the Squidward folder.
And then you also want to open up the game handler on the client.
So that's in Starter Player scripts.
You'll open up the game handler, and we're also going to open up the game scenes module script in the
modules section on the client.
So to get started we're going to go to our game service.
And we're going to listen for when our basement part gets touched.
The first thing we need to verify is if we're ready for section number two.
If we are not ready for section two, then we do not care about our basement part getting touched.
So we're just going to return.
We're also going to get the part that touched this part.
And we still want to verify whether or not a character or a player touched this part.
Right?
So if not other part dot parent find first child which is a humanoid, then we're going to return.
And basically we could actually just copy the exact same thing that we did up here to make sure that
a player has touched our basement part.
After that, we can create a boolean to keep track of when this part gets touched.
So that way we don't execute this function more than once.
So we'll create a new boolean up here and we'll call it basement touched.
And we'll set that to false for now.
And we can go back and check if basement touched then we're just going to return.
Otherwise we can set basement touch equal to true.
And afterwards we can refer to our sections module script and start our section number two.
So hopping into our game sections module script, we're now going to start scripting inside of this
function.
What we can do in here is we can leave out a warning message to say starting section two of the game.
And then we're going to use our game comms event, and we're going to fire to all of the clients in
our game that we need them to change their sound into the basement so we can do game comms enum for
the client to client, and we want to change their sound to the basement.
That way any sounds that are outside or in the restaurant are going to be muffled.
Then we're going to use the game comms event again and fire to all of the clients that we need them
to start the stairs scene.
So game comms enum on the client two client and there is a scene for us to start, which is the stairs
scene.
So inside of our game handler module script.
As you can see, when we're given the action to start the stair scene, this is where we're going to
use the scenes module script on the client to start the animation for the stair scene, and we can go
ahead and fill it out real quick, because it's actually not that complicated.
All we're going to do when we need to start our stair scene is we want to first make sure that the player
isn't on the dead team.
So what we could do is we could get access to the team service up here.
Game get service teams.
And if our local player team is equal to the team's dead, then we're just going to ignore this command.
Otherwise, we're going to set the current camera camera type equal to the enum dot camera type dot
scriptable.
And then we're going to use our tween service and create a tween on our camera.
We can do a tween info dot new of like one second and an enemy's style of let's say sine.
And we're going to want to move the C frame of our camera.
And that C frame is going to be equal to a part in the workspace.
So in the workspace dot filtering folder we can get our camera parts folder.
And we have a part in there called facing the stairs.
And then we can get the C frame of that part.
Now we can go ahead and play this tween.
And that's all we need to do for the stair scene.
That's it.
So we can go back into our game sections module script.
And another thing we'll want to have the clients do is to play the ambience inside of the basement.
So game comms event fire to all the clients.
Again we're going to use the game comms enum client to client dot play sound.
And the sound instance is going to be inside of the sound service dot ambience.
And there is the basement ambience.
So I'll play that real quick for you.
We'll go to the basement ambience and we'll play this.
So it's going to be a creepy kind of intense ambience that we're going to be playing inside of the basement.
And of course we can set play at point equal to false.
And now what we're going to do is we're going to loop through every single player that is inside of
our alive team.
So in teams dot alive, get players, we want to go ahead and teleport them around a specific point
so we can use our teleport player around keyframe function.
We're going to pass this player.
And then inside of the workspace dot filtering folder inside of the teleport parts folder, there is
our basement part, and we're going to get the keyframe of that.
So when we go to our basement, here's our part.
We're just going to teleport our players randomly around this part four studs this way or four studs
that way, four studs that way and four studs this way.
So that way they should all be grouped up around this general area here.
And after we do that, we want to stop the players from being able to exit the basement.
So inside of the workspace dot filtering folder, there is a part in there called stairs blocking wall.
And we're going to set the can collide for that equal to true.
So if we actually go to our filtering folder and we find the stairs blocking wall, here it is.
This part is going to prevent our players from being able to climb up the stairs and leave the basement
afterwards.
What we're going to do is we're going to refer to our Squidward that we're just going to animate so
we can call it animate Squidward.
And he's inside of the server storage.
Other stuff folder and he is the handsome Squidward anime and not the AI.
And we're going to go ahead and put him inside of the workspace.
So we're going to set his parent equal to the workspace, and we can just put him in the characters
folder.
So he's going to be positioned right above here, and his eyes are going to be glowing.
And that's when we tween the players camera to this position here.
He's going to push this box.
And this box is going to crush these stairs and destroy them.
And they're going to see him standing in the background all animated with his eyes glowing.
So when we go to server storage and go to other stuff and we find handsome Squidward Animate and we
go ahead and set his parent equal to the workspace, he's going to be standing right back here with
his eyes glowing.
Of course the lights are going to be off, so the only thing you'll see is his face, so we can go ahead
and move him back inside of server storage.
So put him back in the other stuff folder.
Because we're actually going to need to animate the Squidward, and the only animation we're going to
need to do on him is just his idling animation.
And we actually have a module script, which is our handsome Squidward animate that we're going to use
to start and stop the animations on him.
So inside of here, all we're going to do is refer to the server storage equal to game get service server
storage.
We'll have a table to represent this module script.
So animation handler is equal to a table.
And we'll make sure to return that at the end of our script.
And inside of here we can have a function and animation handler to start his animation.
And then we can have a function to stop his animation as well.
We're going to want to make a reference to him so we can call it handsome.
Squidward for animation is equal to server storage.
Other stuff.
Handsome.
Squidward.
Animate.
And then we can get his idle animation, which is inside of handsome squid.
Word for animate animations dot idle animation.
So if you go into the server storage and you go to your handsome Squidward Animate, he has a folder
with his idle animation and basically the only ID you need to copy in here is the exact same one that
you put in for your handsome Squidward AI when we initially set up the game.
If you haven't uploaded the animations yet, make sure you put him in the workspace and you open up
the animation editor on him and load all of the different animations and publish them to Roblox.
And then you can copy their IDs and put them inside of the different animation instances.
Underneath his animation script, and then you can take the same idalene animation and put it inside
of the idle animation for our handsome Squidward anime.
Then we can go ahead and get the track for this idle animation.
So idle track is equal to the handsome Squidward for annum dot humanoid dot animator.
And we're going to load the animation idle anim.
And then this is really easy.
We'll just refer to our idle track and then play it here.
And then down here we'll just refer to our idle track and then stop it here.
And that's all we need to do for this module script.
So now we can go back to our game sections.
And what we could do here is we could refer to this module script, which means we're going to have
to require it first of all.
So up here we can create a variable.
We'll call it Squidward Animation Handler.
And that's going to be equal to the table that we get inside of server script service, dot server,
dot modules, dot Squidward, and then we get the handsome Squidward animate.
And now that we have this table, we can go down here and refer to our Squidward animation handler and
we can start his animation.
And now the next thing we need to do is while our players cameras are staring down at the stairs, we
want to refer to a crate in the workspace that's going to be pushed so we can make a variable called
crate, and that's equal to the workspace dot Krusty Krab.
And we're going to get the pushed crate.
And inside of this pushed crate we have a particle emitter that we're going to emit particles out of
on each of these stair parts that we destroy.
And we also have a light inside of this crate just to make sure it's easier to see, because it's going
to be pitch black up here.
So we actually want them to see this crate being pushed down.
But basically we're going to emit like 60 particles out of each of these stair instances.
That gets hit.
So we'll emit something like that to show like broken particles flying off.
Though, we'll make our reference to the push crate.
And what we're going to do is we're going to connect to the touched event of this crate so we can call
it connection, and it's equal to the crate dot touched event.
And we're going to connect a Lambda function to this and get the other part that touched it.
And we want to make sure that this other part has a name of stair step.
So each one of these stairs has a name stair step.
And if this box touches one of those we want to destroy it.
So if this other part dot name is not equal to stair step.
Then all we're going to do is just return out of the function.
Otherwise what we could do is we could set this other part, transparency equal to one to make it invisible,
set the other part can collide equal to false.
And then we can get a clone of the particle emitter inside of the crate.
So crate dot particle emitter will clone this and set the parent of the clone equal to the other part.
And then we're going to use the game comms event and fire to all the clients to play a sound.
So game comms client to client play sound.
The sound instance is going to be inside of the sound service.
SFX dot would break.
So this is the sound we're going to play when the wood breaks.
And I'll just play it real quick for you.
Sounds like this.
There we go.
And then once we do that, we can refer to our clone and emit something like 60 particles out of it.
Once we do this, we're going to wait something just like two seconds.
So that way, once the player's camera stare down at the stairs, they're going to be staring for about
two seconds.
And then after those two seconds, we're going to push that crate down the stairs.
So we're going to have to get our crate and make it unanchored.
So anchored is equal to false.
And we're also going to set the network ownership of the crate to the server.
So we pass nothing to this function, because we want the server to have network ownership over the
crate.
And then we're going to refer to the crates dot assembly linear velocity.
And this is how we're going to be able to throw it.
And we want to set this assembly linear velocity equal to a new vector three which represents the direction
of the force we want to push it towards.
The higher the number then the greater the force.
In our example, since the x axis is going this way, right?
We want to push this crate in this direction which is going in the negative x direction.
So.
We can pass a value of like -30 to push this crate in that direction.
And then we could just do zero for the y axis and zero for the z axis.
Then we'll just wait for like five seconds.
So as the crate is falling down the stairs, it's destroying a bunch of stair parts.
And then afterwards we're going to refer to that connection and disconnect it that way we're not listening
for when the crate is touched anymore.
Then we can make the crate anchored again.
And then we're going to set the point light inside of the crate enabled equal to false.
And that means we're actually going to have to enable it in the first place.
So.
When we start the animation and things like that.
Um, actually, when we first get the crate, we can just go here.
And set the point light enabled equal to true.
Another thing that we could do, actually, is we could move this action right here.
So before the players move their camera to the part in the workspace, we want to make sure that we've
actually put the Squidward and we've actually enabled the light on the crate.
So after we enable the light, then we can fire to all the clients to start the stair scene or move
their camera to that part.
Then we push the crate.
The crate destroys a whole bunch of stuff, blah blah blah.
And then after that, when the crate is finished destroying stuff and we've anchored it, then we're
going to use our manipulate cam event and fire to all of the clients to go ahead and reset their cameras
back to their character.
So camera manipulation enum dot two client dot reset camera.
And actually something that's very important about this is that we should do it only to the players
that are in the alive team.
So for every single player in Teams Alive, get players.
Instead, we'll just use this manipulate cam event and fire to a particular client.
So we're just going to loop through different clients.
We'll pass the player and then the action.
So they'll reset all of their cameras.
And then we can use our update guy event and fire to all of the clients.
Now we want to tell them that they fulfilled the objective of entering the basement.
So G actions enum objective fulfilled.
And that fulfilled objective name is equal to go to basement.
And now that means we're going to want to give them a new objective, which is to restore the power
in the basement so it can go back up to where our objectives are stored.
And we're going to create a new one.
So that's going to be restore power.
And we can set the text for this one to be equal to something like figure out how to restore the power.
You just do that?
Why not?
And then we'll have a boolean to keep track of whether or not this was fulfilled.
False.
By default.
We'll go back down.
And then we can use the update GUI event and fire all to the client's GUI actions.
Enum dot add objective.
The objective we would like to add is our restore power.
And then we're going to set the text equal to sections or game sections.
Dot objectives dot restore power and get the text in there.
And then one last time we're going to use our update UI event and fire to all of the clients to give
them some information on how to obtain the flashlight, which is going to be on the floor.
So we can do GUI actions, enum dot, small message, and we're going to want to tell them that they
need to grab the flashlight from the floor.
Now, after this point, basically all of the players cameras have returned back to their characters.
So we'll just wait one second just in case.
But after that, we're going to refer to our Squidward animation handler, and we're going to stop the
animation inside of there.
And then we're just going to set the animated Squidward dot parent equal to server storage and put him
back in the other stuff folder, or you could destroy him as well.
Doesn't really matter either way.
Okay.
And perfect.
We should have everything completed here that we need to test so far.
So let's go ahead and play test the game and check to see if our basement scene is working or not.
All right, it is now time to go ahead and inspect the basement.
So as soon as we touch this invisible part right here, our camera should get moved up to here.
The stairs scene should start and then our camera should move back.
So let's go ahead and see what happens.
So we touch it.
There we go.
We're currently in the stair scene.
The crate gets pushed down.
Spooky.
Squidward is back there.
We get told to grab the flashlight from the floor.
Currently we don't have that scripted, but we'll do that later.
And as you can see, we are no longer able to exit the basement as we're stuck from doing so, our crate
is laying back there, and if we go ahead and look on the server real quick and I go down to the basement
here and let me go ahead and move this character so we can actually see whether or not we broke any
stairs.
Move his light up.
And there you go.
As you can see, a whole bunch of stairs are missing because they all got destroyed by our crate.
Perfect.
So now this is the time where we're going to let our players basically have free reign over the basement.
They're going to get their flashlight, and they're going to explore the basement to figure out how
to restore the power.
So everything is working well except for my animation, because I put in the wrong ID, but that's fine.
So the next thing we can go ahead and script, I think, is the lockers for players to be able to hide
inside of them, because our Squidward AI is going to be pretty ruthless, and we need to give our players
the ability to hide inside of lockers in the map.
So as you can see, I've already placed them around the map.
They have different positions in them, so when the player goes up to the locker, we'll put them inside
and we'll tween them coming out and things like that, and it'll be pretty interesting to see.
So I'll go ahead and see you in the next lecture.